﻿using System;
using System.Collections.Generic;
using UnityEngine;
using Yoozoo.Gameplay.Liberty.World;

namespace Yoozoo.Gameplay.Liberty.AI
{
    [Flags]
    public enum PathType
    {
        None = 0,
        Npc = 1,
        NpcTrafficLight = 2,       // 红绿灯区域
        Car = 4,
        CarTrafficLight = 8,       // 红绿灯区域
    }
    
    [Serializable]
    public class PathData
    {
        public int id;
        public bool loop;
        public PathType pathType;

        public List<PathPointData> pathPoints;

        
        public string prefabPath;   // 预设路径，供编辑模式下使用
        public Vector3 position;

        public float totalLength; 

        public void Init()
        {
            totalLength = 0;
            for (int i = 0; i < pathPoints.Count; i++)
            {
                int ii = i + 1;
                if (ii >= pathPoints.Count)
                    ii = 0;

                totalLength += Vector3.Distance(pathPoints[i].position, pathPoints[ii].position);
            }

            if (pathType == PathType.Npc)
            {
                NpcPathState pathState = WorldState.Ws.AddNpcPathState(id);
                pathState.pathData = this;
            }
        }
        
        public PathPointData GetHeader()
        {
            if (pathPoints!=null && pathPoints.Count > 0)
            {
                return pathPoints[0];
            }
            return null;
        }

        public PathPointData GetTail()
        {
            if (pathPoints!=null && pathPoints.Count > 0)
            {
                return pathPoints[ pathPoints.Count - 1];
            }
            return null;
        }
        
    }
}